<template>
<h1>循环指令</h1>

<ul>
<li v-for="i in 5">{{i}}</li>
</ul>
<hr>
<table border="1px">
  <tr>
    <th>序号</th>
    <th>标题</th>
    <th>价格</th>
    <th>库存</th>
    <th>操作</th>
  </tr>
<!--  每循环一次多一行-->
<tr v-for="(p,index) in productArr">
  <td>{{index+1}}</td>
  <td>{{p.title}}</td>
  <td>{{p.price}}</td>
  <td>{{p.num}}</td>
  <td ><button @click="del(index)">删除</button></td>
</tr>
</table>
</template>
<script setup>
import {ref} from "vue";

const productArr=ref([
  {title:'苹果',price:50,num:10},
  {title:'香蕉',price:60,num:101},
  {title:'西瓜',price:70,num:102},
  {title:'桃子',price:80,num:103}
])

const del=(index)=>{
  if (confirm('您确认删除吗？')){
    productArr.value.splice(index,1)
  }
}
</script>


<style scoped>

</style>